package com.bfmet.common;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.bfmet.common.base.EntityBase;

public final class DAOService {

	private final static EntityManagerFactory emf;

	static {
		emf = Persistence.createEntityManagerFactory("bfmet_db");
	}

	public static EntityManager getEM() {
		return emf.createEntityManager();
	}

	public static void persist(EntityBase entity) {
		EntityManager em = getEM();
		em.getTransaction().begin();
		em.persist(entity);
		em.getTransaction().commit();
		em.close();
	}
	
	public static void merge(EntityBase entity) {
		EntityManager em = getEM();
		em.getTransaction().begin();
		em.merge(entity);
		em.getTransaction().commit();
		em.close();
	}
}
